<template>
  <div class="albumlist">
    <div
      class="album"
      v-for="(item, index) in albums"
      :key="index"
      :class="backColor(index)"
      @click="toAlbumdetails(item.id)"
    >
      <div class="left-img">
        <div class="image">
          <img :src="item.blurPicUrl" />
        </div>
        <p>
          {{ item.name }}
        </p>
      </div>
      <div class="album-name" v-if="item.artists.length !== 0">
        <span @click.stop="toSingerDetails(item.artists[0].id)"
          >{{ item.artists[0].name }}
        </span>
        <span @click.stop="toSingerDetails(item.artists[0].id)">{{
          item.artists.length >= 2 ? item.artists[1].name : ""
        }}</span>
        <span v-if="item.artist.alias.length !== 0">{{
          `( ${item.artist.alias[0]} )`
        }}</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "albumlist",
  components: {},
  props: {
    albums: {
      type: [Array, String, Object]
    }
  },
  data() {
    return {};
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    backColor(index) {
      if (index % 2 !== 0) {
        return "backColor";
      }
    },
    toAlbumdetails(id) {
      this.$router.push({
        name: "albumdetails",
        query: {
          id
        }
      });
    },
    toSingerDetails(id) {
      this.$router.push({
        name: "singerdetails",
        query: {
          id
        }
      });
    }
  }
};
</script>

<style scoped lang="scss">
.albumlist {
  margin-bottom: 30px;
}
.album {
  height: 80px;
  line-height: 80px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  padding: 10px 0;
  &:hover {
    background: #f5f7fa;
  }
  .left-img {
    height: 100%;
    display: flex;
    font-size: 14px;
    .image {
      height: 100%;
      width: 80px;
      img {
        height: 100%;
        width: 100%;
        border-radius: 5px;
        cursor: pointer;
      }
    }
    p {
      margin: 0 20px;
      cursor: pointer;
      font-size: 14px;
      span {
        color: #ccc;
        font-size: 14px;
      }
    }
  }

  .album-name {
    width: 600px;
    font-size: 14px;
    span {
      &:nth-child(3) {
        font-size: 12px;
        color: #ccc;
      }
    }
  }
}
.backColor {
  background: #fafafa;
}
</style>
